<template>
	<view class="page">
		
		<view class="page-content ">
			<u-tabs :list="tabList" active-color="#70B52C" :is-scroll="true" :current="current"
				@change="change"></u-tabs>
			<view v-if="themeList.length>0" class="theme-list bt bm pt20 pl15 pr15  bg-white">
				<view class="item" v-for="(item,index) in themeList" @click="themeClick(index)" :key="index"
					:class="curTheme==index?'on':''">
					<view class="item-img w48 h48 brs-50">
						<image :src="item.picUrl" class=" w48 h48 brs-50" mode="aspectFit"></image>
					</view>
					<view class="item-title fz12 mt10">{{item.name}}</view>
				</view>
			</view>
			<view class="">



				
				<view class="u-flex bg-white" style="flex-wrap: wrap;">
					<view style="" @click="toInfo(item)" style="width: 50%;min-width: 50%;" class="mb10"
						v-for="(item,index) in dataList" :key="index">

						<view>
							<view class="p15">

								<view class="u-flex u-f-justify">
									<image :src="item.picUrl" style="height:340rpx;" mode="heightFix"></image>
								</view>
								<view class="u-flex u-f-jsb fz14" style="color: #19291C;">
									<span>{{item.name}}</span>
									<span>￥{{item.price}}</span>
								</view>
							</view>
						</view>
					</view>
				</view>
				<view class=" mt10">

					<u-loadmore :status="loadStatus" v-if="dataList.length>0" />
				</view>
				<view class="order-none u-flex u-f-justify fz16 c9 p50" v-if="dataList.length<=0">
					暂无数据！
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		getPlatform
	} from '@/config/util.js'
	export default {
		data() {
			return {
				background: {
					background: ''
				},
				tabList: [],
				otherTabList: [],
				curTab: 2,
				currentType: 1,
				curTheme: 0,
				current: 0,
				loadStatus: 'more',
				scrollHeight: 300,
				dataList: [],
				themeList: [],
				page: 1,
			}
		},
		computed: {
			tabbarList() {
				return this.$store.state.tabbarList || '';
			},
		},
		onLoad(e) {

			this.$nextTick(() => {
						this.$api.categoryAll({
							parentId: 17,
						}, res => {
							if (res.code == 200) {
								res.data.some((item,index)=>{
									if(item.id==e.id){
										this.current=index
									}
								})
								this.tabList=res.data
					this.getSecondList()
							}
						})
			})

		},
		onShow() {},
		// 页面下拉到底部触发
		onReachBottom() {
			if (this.loadStatus == 'more') {
				this.getData()
			}
		},
		methods: {
			toInfo(item) {
				uni.navigateTo({
					url: '/pages/product/info?id=' + item.id
				})
			},
			change(e) {
				this.current = e
				this.getSecondList()

			},
			themeClick(idx) {
				this.curTheme = idx
				this.initData()
			},
			getSecondList() {

				this.$api.categoryAll({
					parentId: this.tabList[this.current].id,
				}, res => {
					if (res.code == 200) {
						this.themeList = res.data
						this.initData()
					}
				})
			},
			initData() {
				this.page = 1
				this.dataList = []
				this.getData()

			},
			toEdit(id) {
				uni.navigateTo({
					url: '/pages/order/confirm?order_id=' + id
				})
			},
			getData() {
				console.log(this.currentType, 111111111)
				let post = {
					pageNo: this.page,
					pageSize: 10,
					categoryId: this.themeList[this.curTheme].id
				}
				this.$api.productSearch(post, res => {
					if (res.code == 200) {
						let _list = res.data.list
						this.dataList = [...this.dataList, ..._list]
						// 判断所有数据是否请求完毕
						if (res.data.total > this.dataList.length) {
							this.page++
							this.loadStatus = 'more'
						} else {
							this.loadStatus = 'noMore'
						}
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	page {
		background: #f5f5f5;
	}

	.module-btn {
		.btn {
			background: rgba(137, 195, 255, 0.3);
			color: rgb(26, 109, 255);
			height: 54upx;
			display: flex;
			align-items: center;
			justify-content: center;
			flex: 1;
			font-size: 24rpx;
			padding: 0 30rpx;
			border-radius: 50rpx;
			text-align: center;
			margin-left: 20rpx;
		}
	}

	.ic-video {
		position: absolute;
		top: 30rpx;
		right: 30rpx;
		font-size: 60rpx;
		z-index: 2;
	}

	.theme-list {
		display: flex;
		text-align: center;

		.item {
			padding: 0 30rpx 30rpx;

			&.on {
				border-bottom: 1px solid #70B52C;

				.item-img {
					border: 1px solid #70B52C;
				}
			}
		}

		.item-img {
			overflow: hidden;
			background: #F4F4F4;
		}

		.item-title {
			color: #19291C;
		}
	}
</style>